<template>
  <div class="app-container">
  <div class="filter-container">
        
        <el-input clearable v-model="search.number" placeholder="按揭单号" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.contractnumber" placeholder="订单合同号" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.customername" placeholder="客户姓名" style="width: 170px;margin:0 5px;"></el-input>
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>

        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="100" align="center" label="订单合同号">
        <template slot-scope="scope">
          <span>{{ scope.row.contractnumber }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭单号">
        <template slot-scope="scope">
          <span>{{ scope.row.loannumber }}</span>
        </template>
      </el-table-column>

      <el-table-column  min-width="100" align="center" label="客户姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.customername }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭金额">
        <template slot-scope="scope">
          <span>{{ scope.row.loanmoney }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭年限">
        <template slot-scope="scope">
          <span>{{ scope.row.loanyear }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="销售顾问">
        <template slot-scope="scope">
          <span>{{ scope.row.guider }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭银行">
        <template slot-scope="scope">
          <span>{{ scope.row.loanbank }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭合同号">
        <template slot-scope="scope">
          <span>{{ scope.row.loancontract }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="已录入返利">
        <template slot-scope="scope">
          <span>{{ scope.row.recordrebate?'是':'否' }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="按揭状态">
        <template slot-scope="scope">
          <span>{{ scope.row.loanstate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="是否返利">
        <template slot-scope="scope">
          <span>{{ scope.row.rebatestate?'是':'否' }}</span>
        </template>
      </el-table-column>

      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  width="380" fixed="right">
        <template slot-scope="scope">
            <el-button type="danger" size="small" @click="loanClick(scope.row.id)">办理</el-button>
            <el-button type="danger" size="small" @click="loanClick(scope.row.id)">返利</el-button>
          <router-link :to="'/presalemanage/agency/loandetails/'+scope.row.id">
            <el-button type="primary" size="small" style="margin-left:5px;">
              详情
            </el-button>
          </router-link>
          
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="fetchData" />

<!-- 办理 -->
<el-dialog :title="dialogLoan.title" :visible.sync="dialogLoan.visible"  width="700px">
    <div class="ci">
        <div class="item">
            <span class="name required">按揭银行</span>
            <span class="value">
                <el-select v-model="dialogLoan.data.loanBank" clearable placeholder="--" style="width: 220px;">
                    <el-option 
                    v-for="(item,index) in selectOptions.loanBank"
                    :key="index"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                
            </span>
        </div>
        <div class="item">
            <span class="name required">按揭合同号</span>
            <span class="value">
                <el-input v-model="dialogLoan.data.loannumber" style="width:220px" ></el-input>
            </span>
        </div>

        <div class="item">
            <span class="name required">按揭金额</span>
            <span class="value">
                <el-input v-model="dialogLoan.data.money" style="width:220px" ></el-input>
            </span>
        </div>
        <div class="item">
            <span class="name required">按揭年限</span>
            <span class="value">
                <el-input v-model="dialogLoan.data.year" style="width:220px" ></el-input>
            </span>
        </div>
        <div class="item">
            <span class="name required">办理完成时间</span>
            <span class="value">
                <el-date-picker v-model="dialogLoan.data.completetime" type="date" placeholder="选择日期"></el-date-picker>
            </span>
        </div>
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialogLoan.visible = false">取 消</el-button>
        <el-button type="primary" @click="saveLoanClick()" :loading="dialogLoan.saveloading">保 存</el-button>
    </div>
</el-dialog>
<!-- end 办理 -->



  </div>
</template>

<script>
import * as agencyApi from '@/api/presale/agency'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'

export default {
    components: { Pagination },
    data(){
        return{
          search:{ 
              number:'',
              customer:'',
              phone:'',
              daterange:'',
              nothavedorder:true
          },
          listQuery: {
                page: 1,
                rows: 20,
                name:'',
                phone:'',
                state:-1,
                daterange:''
          },
          list:null,
          listLoading:false,
          total:0,
          selectOptions:{
            loanBank:[]
          },

          dialogLoan:{
              visible:false,
              saveloading:false,
              title:'按揭办理',
              data:{
                  id:'',
                  loanBank:'',
                  money:'',
                  loannumber:'',
                  year:'',
                  completetime:''
              }
          },

          
        }
    },
    created(){
        var that=this;
        
        that.fetchData();
    },
    filters:{
      parseHandingType(val){
        return ['无','已办理','未办理'][val];
      },
      parsePayType(val){
        return enumHelper.presale.payType.getName(val);
      },
      parseSalesState(val){
        return enumHelper.presale.salesState.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            agencyApi.getLoanList({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
                that.total=res.data.total;
              }
            })
        },
        applyRegisterClick(){
          
        },
        loanClick(id){
          this.dialogLoan.data.loanType='';
          this.dialogLoan.visible=true;
        },
        registerFeeClick(){
          var that=this;
          
        },
        
    }
}
</script>

<style>

</style>